package com.qjc.filter;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Created by timo on 2017/12/27.
 */
public class CustomServletOutputStream extends ServletOutputStream {
    private OutputStream outputStream;

    private ByteArrayOutputStream byteArrayOutputStream;


    public CustomServletOutputStream(OutputStream outputStream) {
        this.outputStream = outputStream;
        byteArrayOutputStream = new ByteArrayOutputStream();
    }

    @Override
    public boolean isReady() {
        return false;
    }


    @Override
    public void setWriteListener(WriteListener writeListener) {


    }
    @Override
    public void write(int b) throws IOException {
        outputStream.write(b);
        byteArrayOutputStream.write(b);
    }


    public byte[] getCopy() {
        return byteArrayOutputStream.toByteArray();
    }
}
